<template>
  <div class="page-container" style="min-width: 1170px;" v-loading="loading">
    <ex_header_spiler :title="$tt('label_base_info')"></ex_header_spiler>
    <ex_super_desc v-bind="baseOption" :data="form" :attrs="$defaultDetailDescAttrs" />

    <ex_header_spiler :title="$t('label_task_detail')">
    </ex_header_spiler>
    <ex_super_table v-bind="table" ref="SuperTable">
    </ex_super_table>
  </div>
</template>

<script>
import router_params from '@/mixin/router_params';

export default {
  name: "count_detail",
  title: 'label_stocktaking_detail',
  mixins: [router_params],
  data() {
    return {
      loading: false,
      detailUrl: "/wms-api/inside/CountOrderDetailRpc/selectPage.json",
      orderUrl: "/wms-api/inside/CountOrderRpc/detail.json",
      form: {},
      detailList: [],
      baseOption: {
        model: [
          { key: 'orderNo', label: 'label_stocktaking_order_code', },
          { key: 'bizType', label: 'label_business_type', },

          { key: 'status', label: 'label_status', formatter: (r, c, v, i) => this.$enumShow(v, "CountOrderStatusEnum"), },
          { key: 'type', label: 'label_stocktaking_type', formatter: (r, c, v, i) => this.$enumShow(v, "CountOrderTypeEnum"), },
          { key: 'mode', label: 'label_stocktaking_way', formatter: (r, c, v, i) => this.$enumShow(v, "CountOrderModeEnum"), },
          // { key: 'isDiff', label: 'label_is_diff', formatter: (r, c, v, i) => this.$enumShow(v, "YesOrNoEnum"), },
          // { key: 'diffNum', label: 'label_diff_count', },
          { key: 'totalLocationNum', label: 'label_warehouse_location_count', },
          { key: 'totalSkuCategoryNum', label: 'label_sku_kind', },

          { key: 'totalStockNum', label: 'label_sum_stock', },
          { key: 'creator', label: 'label_create_user', },
          { key: 'gmtCreate', label: 'label_create_time', formatter: (r, c, v, i) => this.$dateFormat(v) },
        ],
      },
      table: {
        autoLoad: false,
        autoPage: true,
        autoFlex: true,
        url: "/wms-api/inside/CountOrderRpc/selectDetailPage.json",
        urlParams: {},
        model: [
          { key: 'taskNo', label: 'label_stocktaking_child_task_code', 'min-width': 150, },

          { key: 'areaCode', label: 'label_warehouse_area_code', 'width': 130, },
          { key: 'locationCode', label: 'label_warehouse_location_code', 'min-width': 130, },
          { key: 'subContainerCode', label: 'label_box_code', 'width': 120, },
          {
            key: 'skuOnlyCode', label: 'label_sku_only_code', 'min-width': 130,
            formatter: (r, c, v) => r.skuId < 0 ? "——" : v
          },
          {
            key: 'skuName', label: 'label_sku_name', 'width': 120, 'show-overflow-tooltip': true,
            formatter: (r, c, v) => r.skuId < 0 ? "——" : this.$formatNameCode(v, r.skuNameEn)
          },

          {
            key: 'stockNum', label: 'label_stock_count', 'width': 100, 'show-overflow-tooltip': true,
          },
          {
            key: 'firstCountNum', label: 'label_initial_inventory_box_condition', 'width': 100, 'show-overflow-tooltip': true, if: () => this.TOB,
            render: (h, { row, column }) => {
              const value = row[column.property]

              return (<div class={value != undefined ? (value > 0 ? 'color_success' : 'color_danger') : 'color_info'}>
                {value != undefined ? (value > 0 ? this.$t('label_exist') : this.$t('label_lack')) : this.$t('label_wait_operate')}
              </div>)
            },
          },
          { key: 'firstCountNum', label: 'label_first_stocktaking_count', },
          { key: 'firstCountUser', label: 'label_first_stocktaking_user', },
          {
            key: 'secondCountNum', label: 'label_repeated_inventory_box_condition', 'width': 100, 'show-overflow-tooltip': true, if: () => this.TOB,
            render: (h, { row, column }) => {
              const value = row[column.property]
              return (<div class={value != undefined ? (value > 0 ? 'color_success' : 'color_danger') : 'color_info'}>
                {value != undefined ? (value > 0 ? this.$t('label_exist') : this.$t('label_lack')) : this.$t('label_wait_operate')}
              </div>)
            },
          },
          { key: 'secondCountNum', label: 'label_second_stocktaking_count', },
          { key: 'secondCountUser', label: 'label_second_stocktaking_user', },

          { key: 'isDiff', label: 'label_is_diff', formatter: (r, c, v, i) => this.$enumShow(v, "YesOrNoEnum") },
          { key: 'diffNum', label: 'label_diff_count', },

          { key: 'secondReason', label: 'label_audit_reason', },
        ],

      },
    }
  },
  computed: {

    TOB() {
      return this.form.bizType == 'TOB'
    },

  },

  methods: {
    init_order(id) {
      this.loading = true
      let data = {
        id
      }
      this.$ajax({
        url: "/wms-api/inside/CountOrderRpc/detail.json",
        method: 'post',
        data,
        success: (res) => {
          this.form = res.data
          this.fixTabLabel()
        },
        complete: () => {
          this.loading = false

        }
      })
    },
    fixTabLabel() {
      if (!!this.form.orderNo) {
        this.$emit("tagModifyLabel", {
          _key: 'label_name_code', name: this.$tt("label_stocktaking_detail"),
          code: this.form.orderNo || ''
        })
      } else {
        this.$emit("tagModifyLabel", "label_stocktaking_detail")
      }
    },
    init_data_default(params) {
      this.$refs.SuperTable.loadData({ orderId: params.id })
      this.init_order(params.id)
    },
  }
}
</script>

<style scoped></style>
